package com.ruoyi.project.bas.basCustomerType.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.project.bas.basCustomerType.domain.BasCustomerType;
import com.ruoyi.project.bas.basCustomerType.mapper.BasCustomerTypeMapper;
import com.ruoyi.project.bas.basCustomerType.service.IBasCustomerTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.text.Convert;

/**
 * 供应商基础分类Service业务层处理
 * 
 * @author qxq
 * @date 2023-05-30
 */
@Service
public class BasCustomerTypeServiceImpl implements IBasCustomerTypeService
{
    @Autowired
    private BasCustomerTypeMapper basCustomerTypeMapper;

    /**
     * 查询供应商基础分类
     * 
     * @param supplierTypeId 供应商基础分类主键
     * @return 供应商基础分类
     */
    @Override
    public BasCustomerType selectBasCustomerTypeByCustomerTypeId(Long supplierTypeId)
    {
        return basCustomerTypeMapper.selectBasCustomerTypeByCustomerTypeId(supplierTypeId);

    }

    /**
     * 查询供应商基础分类列表
     * 
     * @param basCustomerType 供应商基础分类
     * @return 供应商基础分类
     */
    @Override
    public List<BasCustomerType> selectBasCustomerTypeList(BasCustomerType basCustomerType)
    {
        return basCustomerTypeMapper.selectBasCustomerTypeList(basCustomerType);
    }

    /**
     * 新增供应商基础分类
     * 
     * @param basCustomerType 供应商基础分类
     * @return 结果
     */
    @Override
    public int insertBasCustomerType(BasCustomerType basCustomerType)
    {
        basCustomerType.setCreateTime(DateUtils.getNowDate());
        basCustomerType.setCreateBy(ShiroUtils.getLoginName());
        basCustomerType.setCustomerTypeId(Long.valueOf(basCustomerType.getCustomerTypeNo()));
        return basCustomerTypeMapper.insertBasCustomerType(basCustomerType);
    }

    /**
     * 修改供应商基础分类
     * 
     * @param basCustomerType 供应商基础分类
     * @return 结果
     */
    @Override
    public int updateBasCustomerType(BasCustomerType basCustomerType)
    {
        basCustomerType.setUpdateTime(DateUtils.getNowDate());
        return basCustomerTypeMapper.updateBasCustomerType(basCustomerType);
    }

    /**
     * 批量删除供应商基础分类
     * 
     * @param supplierTypeIds 需要删除的供应商基础分类主键
     * @return 结果
     */
    @Override
    public int deleteBasCustomerTypeByCustomerTypeIds(String supplierTypeIds)
    {
        return basCustomerTypeMapper.deleteBasCustomerTypeByCustomerTypeIds(Convert.toStrArray(supplierTypeIds));
    }

    /**
     * 删除供应商基础分类信息
     * 
     * @param supplierTypeId 供应商基础分类主键
     * @return 结果
     */
    @Override
    public int deleteBasCustomerTypeByCustomerTypeId(Long supplierTypeId)
    {
        return basCustomerTypeMapper.deleteBasCustomerTypeByCustomerTypeId(supplierTypeId);
    }

    /**
     * 查询供应商基础分类树列表
     * 
     * @return 所有供应商基础分类信息
     */
    @Override
    public List<Ztree> selectBasCustomerTypeTree()
    {
        List<BasCustomerType> basCustomerTypeList = basCustomerTypeMapper.selectBasCustomerTypeList(new BasCustomerType());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (BasCustomerType basCustomerType : basCustomerTypeList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(basCustomerType.getCustomerTypeId());
            ztree.setpId(basCustomerType.getParentId());
            ztree.setName(basCustomerType.getCustomerTypeName());
            ztree.setTitle(basCustomerType.getCustomerTypeName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
